from typing import Type, Generic, TypeVar, List
from app.extensions import Session
from sqlalchemy import select
from sqlalchemy import select
from app.models.Clas import Clas
from app.models.Student import Clas

ModelType = TypeVar('ModelType', bound='Base')  # 所有的模型都继承自 Base


class BaseRepository(Generic[ModelType]):
    def __init__(self, model: Type[ModelType], db: Session):
        self.model = model  # 代表当前使用的是哪个Model
        self.db = db  # 表示session

    def get_all(self) -> List[ModelType]:  # 示例，返回所有数据
        return self.db.query(self.model).all()

    def get_like_name(self, name: str) -> List[ModelType]:  # 示例，根据关键字返回数据
        return self.db.query(self.model).filter(self.model.name.like(f"%{name}%")).all()

    def get_by_id(self, id: int) -> ModelType | None:
        pass

    def get_by_name(self, name: str) -> ModelType | None:
        pass

    def create(self, info: dict | List[dict]) -> bool:
        pass

    def update(self, id: int, info: dict) -> bool:
        pass

    def delete(self, id: List[int] | int) -> bool:
        pass
